package server.content.skills.wc;

import java.util.LinkedList;
import java.util.List;

public class GlobalTreeHandler {

	private final List<GlobalTree> trees = new LinkedList<GlobalTree>();

	public void processTrees() {
		for (final GlobalTree tree : trees) {
			if (tree == null)
				continue;
			tree.processGlobalTree();
		}
	}

	public static boolean isValidTree(final int id) {
		for (final Trees tree : Trees.values()) {
			for (final int _id : tree.getTreeIds()) {
				if (id == _id) {
					return true;
				}
			}
		}
		return false;
	}
	
	public void registerTree(final int id, final int x, final int y) {
		final int maxLogs = Trees.getTreeForId(id).getMaxLogs();
		trees.add(new GlobalTree(id, maxLogs, x, y, Trees.getTreeForId(id)
				.getRespawnTime()));
	}

	public boolean treeExists(final int x, final int y) {
		for (final GlobalTree tree : trees) {
			if (tree.getX() == x && tree.getY() == y) {
				return true;
			}
		}
		return false;
	}

	public GlobalTree getTree(final int x, final int y) {
		for (final GlobalTree tree : trees) {
			if (tree.getX() == x && tree.getY() == y) {
				return tree;
			}
		}
		return null;
	}

}
